package com.kai.mqtt.message.service.impl;

import com.kai.mqtt.message.WillMessage;
import com.kai.mqtt.message.service.IWillMessageService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author weijk
 * @since 2024/6/9
 */
@Service
public class WillMessageServiceImpl implements IWillMessageService {

    private static final Map<String, WillMessage> MAP = new ConcurrentHashMap<>();

    /**
     * 保存遗嘱消息
     *
     * @param clientId    客户端 id
     * @param willMessage 遗嘱消息
     */
    @Override
    public void put(String clientId, WillMessage willMessage) {
        MAP.put(clientId, willMessage);
    }

    /**
     * 删除遗嘱消息
     *
     * @param clientId 客户端 id
     */
    @Override
    public void remove(String clientId) {
        MAP.remove(clientId);
    }

    /**
     * 获取遗嘱消息
     *
     * @param clientId 客户端 id
     * @return 遗嘱消息
     */
    @Override
    public WillMessage get(String clientId) {
        return MAP.get(clientId);
    }
}
